﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HCY.CTP.DBShangZheng;

namespace IFClientDLL.MyCalc.CalcTrade
{
    public class CalcTrade_OnlyRight : CalcTrade_Empty
    {
        public int MinTime { get { return 2; } }
        public int MaxTime { get { return 300; } }
        public int DefaultTime { get { return 100; } }
         private int _limitTime;
         public CalcTrade_OnlyRight(ITryIF tryif, int limitTime)
             : base(tryif)
        {
            _limitTime = limitTime;
        }
         protected override void CalcTrade(IFServerDLL.Model.TradeOnHand tradeOnhand, MyIF myif)
         {
             DateTime dt = tradeOnhand.ListTrade.Select(p => p.TradeTime).FirstOrDefault();
             if ((myif.MarketTime - dt).TotalSeconds > _limitTime)
             {
                 _tryif.Calc.CalcCmd.CloseTrade(this, myif, tradeOnhand);
                 myif.AddCalcMsg(new CalcMsg(this, "Close the trade onhand " + tradeOnhand.Instrument + " " + tradeOnhand.BuyOrSell.ToString()));
             }
             else
             {
                 myif.AddCalcMsg(new CalcMsg(this, " do not need close."));
             }
         }

         public override string CalcName
        {
            get { return "Trade Limit Time "+_limitTime; }
        }
        
    }
}
